//
//  SXChannelModel.m
//  NetEase-News
//
//  Created by 沈欣 on 2017/9/12.
//  Copyright © 2017年 沈欣. All rights reserved.
//

#import "SXChannelModel.h"
#import <YYModel.h>

@implementation SXChannelModel

+ (NSArray *)getChannelModels
{
    // 获取json路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"topic_news.json" ofType:nil];
    // 获取json二进制
    NSData *data = [NSData dataWithContentsOfFile:path];
    // 反序列化
    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    // 取出tList字段对应的字典数组
    NSArray *tList = result[@"tList"];
    // YYModel转模型数组
    NSArray *channels = [NSArray yy_modelArrayWithClass:[SXChannelModel class] json:tList];
    // 数组排列 : 按tid从小到大排列
    channels = [channels sortedArrayUsingComparator:^NSComparisonResult(SXChannelModel *obj1, SXChannelModel *obj2) {
        //从小到大排列
        return [obj1.tid compare:obj2.tid];
    }];
    return channels;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"%@ %@",self.tname,self.tid];
}

@end
